package com.chis.childcheck;

import com.alibaba.fastjson.JSON;
import com.chis.jm.bean.ChildSynInfoBean;
import com.chis.jm.bean.CrTriggerBean;
import com.chis.jm.bean.TriggerBean;
import com.chis.jm.bean.jxc.trace.TraceBean;
import com.chis.jm.bean.ll.MsgBean;
import com.chis.jmdataspark.comm.JedisSerializeUtil;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.Tuple;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 
 * @Description 
 * @Company zwx
 * @author wlj
 * @version 2019年08月09日
 */
public class CheckMain {
    public static void main(String[] args) {
        ShardedJedis jedis = JedisConnect.getInstance().sparkjedisPool.getResource();
        jedis.select(0);
        Set<String> fullKey = new HashSet<>();
        Iterator i$ = jedis.getAllShards().iterator();
        if (i$.hasNext()) {
            Jedis jei = (Jedis) i$.next();
            fullKey.addAll(jei.keys("*"));
        }
        for(String key : fullKey){
            jedis.select(0);
            String offset = jedis.get(key);
            jedis.select(1);
            Set<Tuple> value = jedis.zrangeByScoreWithScores(key.getBytes(), 0, Double.valueOf(offset));
            if(value != null && value.size() > 0){
                System.out.println("=============================== key:"+key);
                if(key.contains("TOPIC_GM") || key.contains("TOPIC_SRV")){
                    Iterator<Tuple> iterator = value.iterator();
                    while (iterator.hasNext()){
                        Tuple t = iterator.next();
                        System.out.println("score:"+t.getScore());
                        TriggerBean triggerBean = (TriggerBean) JedisSerializeUtil.unserialize(t.getBinaryElement());
                        String str = JSON.toJSONString(triggerBean);
                        System.out.println(str);
                    }
                } else if (key.contains("TOPIC_UPINFO")){
                    Iterator<Tuple> iterator = value.iterator();
                    while (iterator.hasNext()){
                        Tuple t = iterator.next();
                        System.out.println("score:"+t.getScore());
                        ChildSynInfoBean childSynInfoBeanTemp = (ChildSynInfoBean) JedisSerializeUtil.unserialize(t.getBinaryElement());
                        String str = JSON.toJSONString(childSynInfoBeanTemp);
                        System.out.println(str);
                    }
                } else if (key.contains("TOPIC_CRGM")){
                    Iterator<Tuple> iterator = value.iterator();
                    while (iterator.hasNext()){
                        Tuple t = iterator.next();
                        System.out.println("score:"+t.getScore());
                        CrTriggerBean crTriggerBean = (CrTriggerBean) JedisSerializeUtil.unserialize(t.getBinaryElement());
                        String str = JSON.toJSONString(crTriggerBean);
                        System.out.println(str);
                    }
                } else if (key.contains("TOPIC_TRACE")){
                    Iterator<Tuple> iterator = value.iterator();
                    while (iterator.hasNext()){
                        Tuple t = iterator.next();
                        System.out.println("score:"+t.getScore());
                        TraceBean traceBean = (TraceBean) JedisSerializeUtil.unserialize(t.getBinaryElement());
                        String str = JSON.toJSONString(traceBean);
                        System.out.println(str);
                    }
                } else if (key.contains("TOPIC_LL_WARN")){
                    Iterator<Tuple> iterator = value.iterator();
                    while (iterator.hasNext()){
                        Tuple t = iterator.next();
                        System.out.println("score:"+t.getScore());
                        MsgBean msgBean = (MsgBean) JedisSerializeUtil.unserialize(t.getBinaryElement());
                        String str = JSON.toJSONString(msgBean);
                        System.out.println(str);
                    }
                }
            }
        }
        System.out.println("===========结束===========");
    }
}
